const app = getApp()

Page({
    data: {
      
    },
    doRegist:function(e){
        var formObject = e.detail.value;
        var username = formObject.username;
        var password = formObject.password; 

        //前端验证
        if (username.length == 0 || password.length == 0){
            wx.showToast({
              title: '用户名或者密码不能为空',
              icon: "none",
              duration: 3000
            })
        }else{
            var serverUrl = app.serverUrl;
            wx.showLoading({
              title: '请等待',
            })
            wx.request({
              url: serverUrl + '/register',
              method: "POST",
              data:{
                  username: username,
                  password: password
              },
              header: {
                  "content-type": "application/json"
              },
              success(res){
                 console.log(res)
                  var status = res.data.status;
                  wx.hideLoading()
                  if (status == 200){
                    wx.showToast({
                        title: "用户注册成功~!!!",
                        icon:"none",
                        duration:3000
                      }),
                      // app.userInfo = res.data.data;
                      //TODO:修改原有的全局对象为本地缓存
                      app.setGloalUserInfo(res.data.data)
                  }else if (status == 500){
                      wx.showToast({
                        title: res.data.msg,
                        icon:"none",
                        duration:3000
                      })
                  }
              }
            })
        }
    },
    goLoginPage:function(){
        wx.navigateTo({
          url: '../userLogin/login',
        })
    }
})